unit calcFunction;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, StdCtrls, Controls, Forms,
    Dialogs, Math, mException, dllWorkClass;

type
   TCalc = function(dataY: array of Double; dataX: array of Double): Double;
   TCalcFunction = Class(TDllWorkClass)
    protected
      aCalcFunc : TCalc;

    public
      constructor Create(dll_path: String); overload;
      destructor  Destroy; overload;

      function calcFunction(dataY: array of Double; dataX: array of Double): Double;
  end;

implementation

constructor TCalcFunction.Create(dll_path: String);
begin
  inherited Create(dll_path);
  self.aCalcFunc := nil;
end;

destructor TCalcFunction.Destroy;
begin
  inherited;
end;

function TCalcFunction.calcFunction(dataY: array of Double; dataX: array of Double): Double;
begin
  if(Length(dataY) <> Length(dataX)) then
    raise TMException.Create('X array and Y array of the function has different size');

  @self.aCalcFunc := GetProcAddress(DllHandle, 'calcFunc');
  if Addr(self.aCalcFunc) = nil then
    raise TMException.Create('Function f(x) not found');
  Result := self.aCalcFunc(dataY, dataX);

end;

end.
